import socket


def get_local_ip():
    """
    获取本地所有IP
    return: IP列表
    """
    local_ips = ["127.0.0.1"]
    for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
        local_ips.append(ip)
        
    local_ips.sort(reverse=True)
    return local_ips


def decode_data(bytes_arr: bytes) -> str:
    '''
    自动尝试不懂字符集进行解码
    :param bytes_arr: 字节数组
    : return: 字符串
    '''
    try:
        msg = bytes_arr.decode(encoding="utf-8")
    except Exception as e:
        msg = bytes_arr.decode(encoding="GBK")
    
    return msg

if __name__ == '__main__':
    print(get_local_ip())   # 打印所有本地IP